package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GxUserDept;
import com.ruoyi.system.service.IGxUserDeptService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医生分配Controller
 * 
 * @author ruoyi
 * @date 2023-01-16
 */
@RestController
@RequestMapping("/system/userDept")
public class GxUserDeptController extends BaseController
{
    @Autowired
    private IGxUserDeptService gxUserDeptService;

    /**
     * 查询医生分配列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GxUserDept gxUserDept)
    {
        startPage();
        List<GxUserDept> list = gxUserDeptService.selectGxUserDeptList(gxUserDept);
        return getDataTable(list);
    }

    /**
     * 导出医生分配列表
     */
    @Log(title = "医生分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxUserDept gxUserDept)
    {
        List<GxUserDept> list = gxUserDeptService.selectGxUserDeptList(gxUserDept);
        ExcelUtil<GxUserDept> util = new ExcelUtil<GxUserDept>(GxUserDept.class);
        util.exportExcel(response, list, "医生分配数据");
    }

    /**
     * 获取医生分配详细信息
     * @return
     */
    @GetMapping(value = "/{deptId}")
    public TableDataInfo getInfo(@PathVariable("deptId") Long deptId)
    {
        startPage();
        List<GxUserDept> list=gxUserDeptService.selectGxUserDeptByDeptId(deptId);
        return getDataTable(list);
    }


    /**
     * 新增医生分配
     */
    @Log(title = "医生分配", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<GxUserDept> gxUserDeptList)
    {
        return toAjax(gxUserDeptService.insertGxUserDept(gxUserDeptList));
    }

    /**
     * 修改医生分配
     */
    @Log(title = "医生分配", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxUserDept gxUserDept)
    {
        return toAjax(gxUserDeptService.updateGxUserDept(gxUserDept));
    }

    /**
     * 删除医生分配
     */
    @Log(title = "医生分配", businessType = BusinessType.DELETE)
	@DeleteMapping
    public AjaxResult remove(@RequestBody GxUserDept gxUserDept)
    {
        return toAjax(gxUserDeptService.deleteGxUserDeptByUserIds(gxUserDept));
    }
}
